package com.gkd.controller.admin;

import com.gkd.pojo.vo.PublishListVO;
import com.gkd.result.Result;
import com.gkd.service.PostService;
import com.gkd.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 仪表盘相关接口
 */
@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/admin/dashBoard")
public class DashboardController {

    @Autowired
    private UserService userService;

    @Autowired
    private PostService postService;

    /**
     * 统计用户总数
     * @return
     */
    @GetMapping("/userCount")
    public Result<Long> userCount(){
        log.info("统计用户总数");
        Long count = userService.count();
        return Result.success(count);
    }

    /**
     * 总观看数
     * @return
     */
    @GetMapping("/postViewSum")
    public Result<Long> postViewCount(){
        log.info("统计总观看数");
        Long sumView = postService.sumView();
        return Result.success(sumView);
    }

    /**
     * 近期文章发布数量
     * @return
     */
    @GetMapping("/publishList")
    public Result<List<PublishListVO>> publishList(){
        log.info("近期文章发布数量");
        List<PublishListVO> publishList=postService.publishList();
        return Result.success(publishList);
    }

    /**
     * 文章分类统计
     * @return
     */
    @GetMapping("/postClassificationStatistics")
    public Result<List<Map<String, Object>>> postClassificationStatistics(){
        log.info("文章分类统计");
        return Result.success(postService.selectCategoryPostCounts());
    }
}
